How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk (you can use the hotkey Ctrl + Alt + I to add a code chunk) and code the solution for the question.
Knit the rmarkdown file (hotkey: Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Blackboard.
gganimate and gifski then restart Rstudio. Use the WHO’s dataset at this link. Make a top-10 bar race by months between countries on the number of deaths by Covid 19.library(gganimate)
library(gifski)
library(tidyverse)
library(ggplot2)
library(knitr)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
df <- df %>% filter(Cumulative_deaths>0)
library(lubridate)
df$month <- month(df$Date_reported)
d1 <- df %>% group_by(month, Country) %>% summarise(mean = mean(Cumulative_deaths))
d2 <- d1 %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=Country, fill=Country, label=Country)) + geom_col()+
geom_text(aes(y = mean, label = Country), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) + scale_x_reverse()+
labs(title = 'Month', x='', y='Total Number of Deaths', fill='Country')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(month)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)
library(gganimate)
library(gifski)
library(tidyverse)
library(ggplot2)
library(knitr)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
df <- df %>% filter(Cumulative_cases>0)
library(lubridate)
df$month <- month(df$Date_reported)
d1 <- df %>% group_by(month, Country_code) %>% summarise(mean = mean(Cumulative_cases))
d2 <- d1 %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=Country_code, fill=Country_code, label=Country_code)) + geom_col()+
geom_text(aes(y = mean, label = Country_code), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) + scale_x_reverse()+
labs(title = 'Month', x='', y='Total Number of Cases', fill='Country')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(month)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
## Warning: Removed 1 rows containing missing values (geom_text).
df <- read_csv('https://covidtracking.com/data/download/all-states-history.csv')
df <- df %>% filter(negativeIncrease>0)
df <- df %>% drop_na(dataQualityGrade)
library(lubridate)
df$month <- month(df$date)
d1 <- df %>% group_by(month, state) %>% summarise(mean = mean(negative))
d2 <- d1 %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=state, fill=state, label=state)) + geom_col()+
geom_text(aes(y = mean, label = state), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Month', x='', y='Total Increase in Negative Cases', fill='state')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(month)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)